package com.jinsi.service.impl;

import com.jinsi.mapper.ScStandard;
import com.jinsi.mapper.ScTuitionApiMapper;
import com.jinsi.pojo.ScClassesStandard;
import com.jinsi.pojo.ScMarketingDepartment;
import com.jinsi.pojo.ScStudentStandard;
import com.jinsi.service.ScTuitionApiServer;
import com.jinsi.utils.MapReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Date : 2022/7/11 19:17
 * 小南不难
 **/
@Service
public class ScTuitionApiServerImpl implements ScTuitionApiServer {
    @Autowired
    private ScTuitionApiMapper scTuitionApiMapper;

    @Override
    public Map<String, Object> getAllThisYearStandard(int classesPeriods) {
        try {
            ScClassesStandard allThisYearStandard = scTuitionApiMapper.getAllThisYearStandard(classesPeriods);
            return MapReturn.getSuccess(allThisYearStandard);
        }catch (Exception e){
            System.out.println("数据访问有问题==========>"+e.getMessage());
            return MapReturn.getError("数据访问出错");
        }
    }

    @Override
    public Map<String, Object> getAllStandardUseing() {
        try {
            List<ScClassesStandard> allStandardUseing = scTuitionApiMapper.getAllStandardUseing();
            return MapReturn.getSuccess(allStandardUseing);
        }catch (Exception e){
            System.out.println("数据访问有问题==========>"+e.getMessage());
            return MapReturn.getError("数据访问出错");
        }
    }

    @Override
    public Map<String,Object> iptStudentStandard(String sid ,int pid) {
        try {
            ScStudentStandard scStudentStandard = new ScStudentStandard();
            scStudentStandard.setSid(sid);
            long oredrid = new Date().getTime();
            //根据学费id查询项目信息
            Map<String, Object> allThisYearStandard = getAllThisYearStandard(pid);
            ScClassesStandard scClassesStandard = (ScClassesStandard) allThisYearStandard.get("data");
            scStudentStandard.setProjectId(oredrid+"");//项目编号
            scStudentStandard.setAmountReceivable(scClassesStandard.getClassesMoney());//应收费用
            scStudentStandard.setProjectName("学费");
            scTuitionApiMapper.iptStudentStandard(scStudentStandard);
            return MapReturn.getSuccess("存储成功");
        }catch (Exception e){
            System.out.println("数据库异常，自动添加学生信息失效==========>"+e.getMessage());
            return MapReturn.getError("存入失败");
        }
    }

    @Override
    public Map<String, Object> getMarketingName(String sid) {
        try {
            return MapReturn.getSuccess(scTuitionApiMapper.getMarketingName(sid));
        }catch (Exception e){
            System.out.println("数据库查询失败=======>"+e.getMessage());
            return null;
        }
    }

    @Override
    public Map<String, Object> getMarketingList() {
        try {
            return MapReturn.getSuccess(scTuitionApiMapper.getMarketingList());
        }catch (Exception e){
            System.out.println("数据库查询失败=======>"+e.getMessage());
            return null;
        }
    }

}
